
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<script>
    $(function () {
        chaxun();
    });
    function chaxun() {
        $.ajax({
            url:'/NavSelect',//访问后台的地址
            type:'get',//访问后台的类型
            //封装传递给后台的数据
            dataType:'json',
            success:function (data) {

                var html = '';
                for (var i = 0; i < data.length; i++) {
                    var status = data[i].status;
                    status = status == 1 ? "启用" : "停用";
                    html += '<tr>\n' +
                        '        <td>' + data[i].id + '</td>\n' +
                        '        <td>' + data[i].href + '</td>\n' +
                        '        <td>' + data[i].title + '</td>\n' +
                        '        <td>' + data[i].status + '</td>\n' +
                        '        <td><input type="button" value="编辑" onclick="update(' + data[i].id + ')"> <input type="button" value="删除" onclick="del(' + data[i].id + ')"> </td>\n' +
                        '    </tr>';
                }
                $("#navTable").html(html);
            }
        })
    }
    //更新数据
    function update(id) {
        localStorage.setItem("navId",id);
        $('#homeRight').load('/back/nav/NavUpdate.jsp');
    }

    function del(id) {
        $.ajax({
            url:'/NavDelete',
            data:{id:id},// json对象
            dataType:'json',// 返回值类型
            type:'post',
            success:function (data) {
                if(data == 1){
                    chaxun();
                }else {
                    alert("很遗憾,操作失败");
                }
            }
        })

    }
</script>
<body>
<%--<a href="javaScript:$('#homeRight').load('/back/NavAdd.jsp')">新增</a>--%>
<table class="table table-hover">
    <thead>
    <tr>
        <td>id</td>
        <td>链接</td>
        <td>标题</td>
        <td>状态</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody id="navTable">

    </tbody>
</table>
</body>
</html>
